home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / misc / emu / amiSPIMsrc.lha / Tests / tt.io.s < prev    next >
Text File  |  1994-01-17  |  3KB  |  165 lines

  1. # SPIM S20 MIPS simulator.
  2. # Test memory mapped IO
  3. # Copyright (C) 1992-1994 James Larus, larus@cs.wisc.edu.
  4. # ALL RIGHTS RESERVED.
  5. #
  6. # SPIM is distributed under the following conditions:
  7. #
  8. # You may make copies of SPIM for your own use and modify those copies.
  9. #
  10. # All copies of SPIM must retain my name and copyright notice.
  11. #
  12. # You may not sell SPIM or distributed SPIM in conjunction with a commerical
  13. # product or service without the expressed written consent of James Larus.
  14. #
  15. # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16. # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. # PURPOSE.
  19. #
  20.  
  21. # $Header: /home/primost/larus/Software/SPIM/Tests/RCS/tt.io.s,v 1.3 1994/01/18 03:23:44 larus Exp larus $
  22.  
  23.  
  24.     .data
  25. prompt: .asciiz "SPIM IO Test.  Please type 6 input lines:\n"
  26. nl:    .asciiz "\n"
  27.     .text
  28.     .globl main
  29. main:
  30.     li $v0, 4
  31.     la $a0, prompt
  32.     syscall
  33.     li $s0, 3        # loop counter
  34.  
  35. l0:
  36.     li $t0, 0xffff0000    # recv ctrl
  37.     li $t1, 0xffff0004    # recv buf
  38.     li $t2, 0xffff0008    # trans ctrl
  39.     li $t3, 0xffff000c    # trans buf
  40.  
  41. l1:
  42.     lw $t4, 0($t0)        # Wait for receiver ready
  43.     and $t4, $t4, 1
  44.     beq $t4, 0, l1
  45.  
  46.     lw $t5, 0($t1)        # Read character
  47.  
  48. l2:
  49.     lw $t4, 0($t2)        # Wait for transmitter ready
  50.     and $t4, $t4, 1
  51.     beq $t4, 0, l1
  52.  
  53.     sw $t5, 0($t3)        # Write character
  54.  
  55.     beq $t5, 0xa, decr    # New line (nl)
  56.     bne $t5, 0xd, l0    # Carriage return (cr)
  57.  
  58. decr:
  59.     add $s0, $s0, -1
  60.     bne $s0, 0, l0
  61.  
  62.  
  63.     .globl main_async
  64. main_async:
  65. l20:
  66.     li $t0, 0xffff0000    # recv ctrl
  67.     li $t1, 0xffff0004    # recv buf
  68.     li $t2, 0xffff0008    # trans ctrl
  69.     li $t3, 0xffff000c    # trans buf
  70.  
  71.     li $s0, 3        # loop counter
  72.  
  73.     li $t4, 0xf        # Enable device interrupts
  74.     sw $t4, 0($t0)
  75.     sw $t4, 0($t2)
  76.     li $t4, 0x301
  77.     mtc0 $t4, $12        # Enable interrupt mask (Status register)
  78.     li $t7, 0        # 1 => char in $t6
  79.  
  80. l21:    b l21
  81.  
  82.     .ktext 0x80000080
  83.     mfc0 $t4, $13        # Get Cause register
  84.     sll $t5, $t4, 2
  85.     and $t5, $t5, 0xf    # ExcCode field
  86.     bne $t5, 0, other
  87.                 # Interrupt:
  88.     and $t5, $t4, 0x100
  89.     beq $t5, 0, check_trans
  90.                 # Recevier interrupt
  91.  
  92.     lw $t5, 0($t0)        # Wait for receiver ready
  93.     and $t5, $t5, 1
  94.     beq $t5, 0, no_recv_ready
  95.  
  96.     lw $t6, 0($t1)        # Read character
  97.     li $t7 1
  98.     b check_tready
  99.  
  100. check_trans:
  101.     and $t5, $t4, 0x200
  102.     beq $t5, 0, bad_int
  103.                 # Transmitter interrupt
  104.  
  105. check_tready:
  106.     lw $t5, 0($t2)        # Wait for transmitter ready
  107.     and $t5, $t5, 1
  108.     beq $t5, 0, no_trans_ready
  109.  
  110.     bne $t7, 1, done
  111.  
  112.     sw $t6, 0($t3)        # Write character
  113.     li $t7, 0
  114.  
  115.     beq $t6, 0xa, decr2    # New line (nl)
  116.     bne $t6, 0xd, done    # Carriage return (cr)
  117.  
  118. decr2:
  119.     add $s0, $s0, -1
  120.     bne $s0, 0, done
  121.  
  122.     li $v0 10    # Exit when done
  123.     syscall        # syscall 10 (exit)
  124.  
  125.  
  126. other:  li $v0, 4
  127.     la $a0, other_str
  128.     syscall
  129.     b done
  130.  
  131. no_recv_ready:
  132.     li $v0, 4
  133.     la $a0, no_recv_str
  134.     syscall
  135.     b done
  136.  
  137. bad_int:
  138.     li $v0, 4
  139.     la $a0, bad_int_str
  140.     syscall
  141.     b done
  142.  
  143. no_trans_ready:
  144.     li $v0, 4
  145.     la $a0, no_trans_str
  146.     syscall
  147.     b done
  148.  
  149. done:
  150.     mfc0 $k1 $14    # EPC
  151.     rfe        # Return from exception handler
  152. #    addiu $k1 $k1 4 # Return to next instruction
  153.     jr $k1
  154.  
  155.     .data
  156. other_str:
  157.     .asciiz "Non-interrupt exception\n"
  158. no_recv_str:
  159.     .asciiz "Receiver not ready\n"
  160. no_trans_str:
  161.     .asciiz "Transmitter not ready\n"
  162. bad_int_str:
  163.     .asciiz "Unknown interrupt\n"
  164.  
  165.